package AcWing周赛;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: a
 * Date: 2022-09-03
 * Time: 19:14
 */
public class Demo67_2 {
    public static boolean check(int n, int m, int[][] q){
        for(int i = 0; i < n; i++){
            int cnt = 0;
            for(int j = 0; j < m; j++){
                if(q[i][j] != j + 1){
                    cnt++;
                }
            }
            if(cnt > 2){
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[][] q = new int[n][m];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                q[i][j] = scanner.nextInt();
            }
        }
        for(int i = 0; i < m; i++){
            for(int j = i; j < m; j++){
                for(int k = 0; k < n; k++){
                    int tmp = q[k][i];
                    q[k][i] = q[k][j];
                    q[k][j] = tmp;
                }
                if(check(n, m, q)){
                    System.out.println("YES");
                    return;
                }
                for(int k = 0; k < n; k++){
                    int tmp = q[k][i];
                    q[k][i] = q[k][j];
                    q[k][j] = tmp;
                }
            }
        }
        System.out.println("NO");
    }
}
